package com.example.yunhailutong.zhongtan.net;


import android.util.Log;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.example.yunhailutong.zhongtan.app.App;
import com.example.yunhailutong.zhongtan.app.OldsEvent;
import com.example.yunhailutong.zhongtan.constant.Url;
import com.example.yunhailutong.zhongtan.entity.ChanPinFenLeiEntity;
import com.example.yunhailutong.zhongtan.entity.CsfcEntity;
import com.example.yunhailutong.zhongtan.entity.DingDanDescEntity;
import com.example.yunhailutong.zhongtan.entity.DingDanListEntity;
import com.example.yunhailutong.zhongtan.entity.GangChangEntity;
import com.example.yunhailutong.zhongtan.entity.GongYingEntity;
import com.example.yunhailutong.zhongtan.entity.GongYingXuQiuEntity;
import com.example.yunhailutong.zhongtan.entity.HangYeZiXunEntity;
import com.example.yunhailutong.zhongtan.entity.HomeEntity;
import com.example.yunhailutong.zhongtan.entity.ImageEntity;
import com.example.yunhailutong.zhongtan.entity.InfoListEntity;
import com.example.yunhailutong.zhongtan.entity.LoginEntity;
import com.example.yunhailutong.zhongtan.entity.PeopleInfoEntity;
import com.example.yunhailutong.zhongtan.entity.UserInfoEntity;
import com.example.yunhailutong.zhongtan.entity.XuQiuEntity;
import com.example.yunhailutong.zhongtan.entity.ZhdjEntity;
import com.example.yunhailutong.zhongtan.net.base.iStringRequest;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import org.greenrobot.eventbus.EventBus;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.io.IOException;
import java.util.Map;

import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.RequestBody;



/**
 * Created by Administrator on 2016/4/26 0026.
 */
public class PersionBiz {
    private final String SUCESS = "1";
    private final String FAILE = "0";
    private final String TOKENSHIXIAO = "-2";
    private Gson gson;
    private RequestQueue mQueue;
    private static OkHttpClient client = null;

    String ADDOLDS = "";

    public PersionBiz() {
        mQueue = App.mQueue;
        gson = new GsonBuilder().serializeNulls().create();
        client = new OkHttpClient();
    }

    //注册
    public void register(Map<String, String> params) {
        final OldsEvent.RegisterEvent message = new OldsEvent.RegisterEvent();
        final iStringRequest request = new iStringRequest(com.android.volley.Request.Method.POST,
                Url.REGISTER,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {
                            JSONObject obj = new JSONObject(response.toString());
                            if (obj.get("Code").equals(SUCESS)) {
                                message.what = 1;
                                EventBus.getDefault().post(message);
                            } else if (obj.get("Code").equals(TOKENSHIXIAO)) {
                                final OldsEvent.TokenShiXiaoEvent tokenmessage = new OldsEvent.TokenShiXiaoEvent();
                                EventBus.getDefault().post(tokenmessage);
                            } else {
                                message.what = -1;
                                message.obj = obj.get("Msg");
                                EventBus.getDefault().post(message);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {
                        message.what = -1;
                        message.obj = "链接失败,请检查网络";
                        EventBus.getDefault().post(message);
                    }
                }).addParams(params);
        mQueue.add(request);
    }

    //获取用户信息
    public void getPeopleInfo(final Map<String, String> params) {
        final OldsEvent.GetPeopleInfoEvent message = new OldsEvent.GetPeopleInfoEvent();
        final iStringRequest request = new iStringRequest(Request.Method.POST,
                Url.GETPEOPLEINFO,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {

                            PeopleInfoEntity entity = gson.fromJson(response.toString(), PeopleInfoEntity.class);
                            if (entity.getCode().equals(SUCESS)) {
                                message.what = 1;
                                message.obj = entity;
                            } else {
                                message.what = -1;
                                message.obj = entity.getMsg();
                            }
                            EventBus.getDefault().post(message);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {
                        message.what = -1;
                        message.obj = "链接失败,请检查网络";
                        EventBus.getDefault().post(message);
                    }
                }).addParams(params);
        mQueue.add(request);
    }

    public void getInfoList(final Map<String, String> params) {
        final OldsEvent.GetInfoListEvent message = new OldsEvent.GetInfoListEvent();
        final iStringRequest request = new iStringRequest(com.android.volley.Request.Method.POST,
                Url.GET_INFO_LIST,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {
                            Log.d("Leon", "******getInfoList*******");
                            InfoListEntity infoListEntity = gson.fromJson(response.toString(), InfoListEntity.class);
                            if (infoListEntity.getCode().equals(SUCESS)) {
                                    message.what = 1;
                                    message.obj = infoListEntity;
                            } else {
                                message.what = -1;
                                message.obj = infoListEntity.getMsg();
                            }
                            EventBus.getDefault().post(message);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {
                        message.what = -1;
                        message.obj = "链接失败,请检查网络";
                        EventBus.getDefault().post(message);
                    }
                }).addParams(params);
        mQueue.add(request);
    }
    //获取智慧党建信息接口
    public void getZhdjInfo() {
        final OldsEvent.ZhdjEvent message = new OldsEvent.ZhdjEvent();
        final iStringRequest request = new iStringRequest(Request.Method.POST,
                Url.PartyInfo,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {

                            ZhdjEntity entity = gson.fromJson(response.toString(), ZhdjEntity.class);
                            if (entity.getCode().equals(SUCESS)) {
                                message.what = 1;
                                message.obj = entity;
                            } else {
                                message.what = -1;
                                message.obj = entity.getMsg();
                            }
                            EventBus.getDefault().post(message);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {
                        message.what = -1;
                        message.obj = "链接失败,请检查网络";
                        EventBus.getDefault().post(message);
                    }
                });
        mQueue.add(request);
    }

    //获取城市风采信息接口
    public void getCsfcInfo() {
        final OldsEvent.CsfcEvent message = new OldsEvent.CsfcEvent();
        final iStringRequest request = new iStringRequest(Request.Method.POST,
                Url.CITYINFO,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {

                            CsfcEntity entity = gson.fromJson(response.toString(), CsfcEntity.class);
                            if (entity.getCode().equals(SUCESS)) {
                                message.what = 1;
                                message.obj = entity;
                            } else {
                                message.what = -1;
                                message.obj = entity.getMsg();
                            }
                            EventBus.getDefault().post(message);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {
                        message.what = -1;
                        message.obj = "链接失败,请检查网络";
                        EventBus.getDefault().post(message);
                    }
                });
        mQueue.add(request);
    }
    //获取首页接口
    public void getHome() {
        final OldsEvent.HomeEvent message = new OldsEvent.HomeEvent();
        final iStringRequest request = new iStringRequest(Request.Method.POST,
                Url.HOME,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {
                            Log.d("Leon", "*******PersionBiz-getHome*********Enter*******");
                            HomeEntity entity = gson.fromJson(response.toString(), HomeEntity.class);
                            if (entity.getCode().equals(SUCESS)) {
                                message.what = 1;
                                message.obj = entity;
                            } else {
                                message.what = -1;
                                message.obj = entity.getMsg();
                            }
                            EventBus.getDefault().post(message);
                            Log.d("Leon", "*******PersionBiz-getHome*********Exit*******");
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {
                        message.what = -1;
                        message.obj = "链接失败,请检查网络";
                        EventBus.getDefault().post(message);
                    }
                });
        mQueue.add(request);
    }

    //登录
    public void login(Map<String, String> params) {
        final OldsEvent.LoginEvent message = new OldsEvent.LoginEvent();
        final iStringRequest request = new iStringRequest(com.android.volley.Request.Method.POST,
                Url.LOGIN,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {

                            LoginEntity loginEntity = gson.fromJson(response.toString(), LoginEntity.class);
                            if (loginEntity.getCode().equals(SUCESS)) {
                                message.what = 1;
                                message.obj = loginEntity;
                            } else {
                                message.what = -1;
                                message.obj = loginEntity.getMsg();
                            }
                            EventBus.getDefault().post(message);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {
//                        message.what = -1;
//                        message.obj = "链接失败,请检查网络";
//                        EventBus.getDefault().post(message);
                    }
                }).addParams(params);
        mQueue.add(request);
    }
    //获取验证码
    public void getCode(Map<String, String> params) {
       // final OldsEvent.LoginEvent message = new OldsEvent.LoginEvent();
        final iStringRequest request = new iStringRequest(com.android.volley.Request.Method.POST,
                Url.GETCODE,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {
                           System.out.print(response.toString());

//                            if (loginEntity.getCode().equals(SUCESS)) {
//                                message.what = 1;
//                                message.obj = loginEntity;
//                            } else {
//                                message.what = -1;
//                                message.obj = loginEntity.getMsg();
//                            }
//                            EventBus.getDefault().post(message);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {
//                        message.what = -1;
//                        message.obj = "链接失败,请检查网络";
//                        EventBus.getDefault().post(message);
                    }
                }).addParams(params);
        mQueue.add(request);
    }






    //获取供应列表
    public void GetGongYingList(Map<String, String> params) {
        final OldsEvent.GongYingEvent message = new OldsEvent.GongYingEvent();
        final iStringRequest request = new iStringRequest(com.android.volley.Request.Method.POST,
                Url.GETGONGYING,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {
                            GongYingEntity loginEntity = gson.fromJson(response.toString(), GongYingEntity.class);
                            if (loginEntity.getCode().equals(SUCESS)) {
                                message.what = 1;
                                message.obj = loginEntity;
                            } else {
                                message.what = -1;
                                message.obj = loginEntity.getMsg();
                            }
                            EventBus.getDefault().post(message);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {
                        message.what = -1;
                        message.obj = "链接失败,请检查网络";
                        EventBus.getDefault().post(message);
                    }
                }).addParams(params);
        mQueue.add(request);
    }

    //获取供应列表
    public void GetXuQiuList(Map<String, String> params) {
        final OldsEvent.XuQiuEvent message = new OldsEvent.XuQiuEvent();
        final iStringRequest request = new iStringRequest(Request.Method.POST,
                Url.GETXUQIU,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {

                            XuQiuEntity entity = gson.fromJson(response.toString(), XuQiuEntity.class);
                            if (entity.getCode().equals(SUCESS)) {
                                message.what = 1;
                                message.obj = entity;
                            } else {
                                message.what = -1;
                                message.obj = entity.getMsg();
                            }
                            EventBus.getDefault().post(message);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {
                        message.what = -1;
                        message.obj = "链接失败,请检查网络";
                        EventBus.getDefault().post(message);
                    }
                }).addParams(params);
        mQueue.add(request);
    }

    //获取资讯列表
    public void GetZiXunList(Map<String, String> params) {
        final OldsEvent.ZiXunEvent message = new OldsEvent.ZiXunEvent();
        final iStringRequest request = new iStringRequest(Request.Method.POST,
                Url.GETZIXUNLIST,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {

                            GangChangEntity entity = gson.fromJson(response.toString(), GangChangEntity.class);
                            if (entity.getCode().equals(SUCESS)) {
                                message.what = 1;
                                message.obj = entity;
                            } else {
                                message.what = -1;
                                message.obj = entity.getMsg();
                            }
                            EventBus.getDefault().post(message);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {
                        message.what = -1;
                        message.obj = "链接失败,请检查网络";
                        EventBus.getDefault().post(message);
                    }
                }).addParams(params);
        mQueue.add(request);
    }

    //获取需求详情
    public void GetXuQiuDesc(Map<String, String> params) {
        final OldsEvent.XuQiuDescEvent message = new OldsEvent.XuQiuDescEvent();
        final iStringRequest request = new iStringRequest(Request.Method.POST,
                Url.GETXUQIUDESC,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {
                            GongYingXuQiuEntity entity = gson.fromJson(response.toString(), GongYingXuQiuEntity.class);
                            if (entity.getCode().equals(SUCESS)) {
                                message.what = 1;
                                message.obj = entity;
                            } else {
                                message.what = -1;
                                message.obj = entity.getMsg();
                            }
                            EventBus.getDefault().post(message);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {
                        message.what = -1;
                        message.obj = "链接失败,请检查网络";
                        EventBus.getDefault().post(message);
                    }
                }).addParams(params);
        mQueue.add(request);
    }

    //获取供应详情
    public void GetGongYingDesc(Map<String, String> params) {
        final OldsEvent.GongYingDescEvent message = new OldsEvent.GongYingDescEvent();
        final iStringRequest request = new iStringRequest(Request.Method.POST,
                Url.GETGONGYINGESC,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {
                            GongYingXuQiuEntity entity = gson.fromJson(response.toString(), GongYingXuQiuEntity.class);
                            if (entity.getCode().equals(SUCESS)) {
                                message.what = 1;
                                message.obj = entity;
                            } else {
                                message.what = -1;
                                message.obj = entity.getMsg();
                            }
                            EventBus.getDefault().post(message);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {
                        message.what = -1;
                        message.obj = "链接失败,请检查网络";
                        EventBus.getDefault().post(message);
                    }
                }).addParams(params);
        mQueue.add(request);
    }

    //获取订单列表
    public void GetDingDanList(Map<String, String> params, final String type) {
        final OldsEvent.DingDanEvent message = new OldsEvent.DingDanEvent();
        final iStringRequest request = new iStringRequest(Request.Method.POST,
                Url.GETDINGDAN,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {
                            JSONObject obj = new JSONObject(response.toString());
                            if (obj.get("Code").equals(SUCESS)) {
                                DingDanListEntity entity = gson.fromJson(response.toString(), DingDanListEntity.class);
                                message.what = 1;
                                message.obj = entity;
                                message.arg1 = type;
                                EventBus.getDefault().post(message);
                            } else if (obj.get("Code").equals(TOKENSHIXIAO)) {
                                final OldsEvent.TokenShiXiaoEvent tokenmessage = new OldsEvent.TokenShiXiaoEvent();
                                EventBus.getDefault().post(tokenmessage);
                            } else {
                                message.what = -1;
                                message.obj = obj.get("Msg");
                                EventBus.getDefault().post(message);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {
                        message.what = -1;
                        message.obj = "链接失败,请检查网络";
                        EventBus.getDefault().post(message);
                    }
                }).addParams(params);
        mQueue.add(request);
    }

    //获取订单详情
    public void GetDingDanDesc(Map<String, String> params) {
        final OldsEvent.DingDanDescEvent message = new OldsEvent.DingDanDescEvent();
        final iStringRequest request = new iStringRequest(Request.Method.POST,
                Url.GETDINGDANDESC,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {
                            JSONObject obj = new JSONObject(response.toString());
                            if (obj.get("Code").equals(SUCESS)) {
                                DingDanDescEntity entity = gson.fromJson(response.toString(), DingDanDescEntity.class);
                                message.what = 1;
                                message.obj = entity;
                                EventBus.getDefault().post(message);
                            } else if (obj.get("Code").equals(TOKENSHIXIAO)) {
                                final OldsEvent.TokenShiXiaoEvent tokenmessage = new OldsEvent.TokenShiXiaoEvent();
                                EventBus.getDefault().post(tokenmessage);
                            } else {
                                message.what = -1;
                                message.obj = obj.get("Msg");
                                EventBus.getDefault().post(message);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {
                        message.what = -1;
                        message.obj = "链接失败,请检查网络";
                        EventBus.getDefault().post(message);
                    }
                }).addParams(params);
        mQueue.add(request);
    }

    //获取订单详情
    public void GetChanPinFenLei(Map<String, String> params) {
        final OldsEvent.ChanPinFenLeiEvent message = new OldsEvent.ChanPinFenLeiEvent();
        final iStringRequest request = new iStringRequest(Request.Method.POST,
                Url.GETCHANPINFENLEI,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {
                            JSONObject obj = new JSONObject(response.toString());
                            if (obj.get("Code").equals(SUCESS)) {
                                ChanPinFenLeiEntity entity = gson.fromJson(response.toString(), ChanPinFenLeiEntity.class);
                                message.what = 1;
                                message.obj = entity;
                                EventBus.getDefault().post(message);
                            } else if (obj.get("Code").equals(TOKENSHIXIAO)) {
                                final OldsEvent.TokenShiXiaoEvent tokenmessage = new OldsEvent.TokenShiXiaoEvent();
                                EventBus.getDefault().post(tokenmessage);
                            } else {
                                message.what = -1;
                                message.obj = obj.get("Msg");
                                EventBus.getDefault().post(message);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {
                        message.what = -1;
                        message.obj = "链接失败,请检查网络";
                        EventBus.getDefault().post(message);
                    }
                }).addParams(params);
        mQueue.add(request);
    }

    //添加订单
    public void AddDingDan(Map<String, String> params) {
        final OldsEvent.AddDingDanEvent message = new OldsEvent.AddDingDanEvent();
        final iStringRequest request = new iStringRequest(Request.Method.POST,
                Url.ADDDINGDAN,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {
                            JSONObject obj = new JSONObject(response.toString());
                            if (obj.get("Code").equals(SUCESS)) {
                                message.what = 1;
                                EventBus.getDefault().post(message);
                            } else if (obj.get("Code").equals(TOKENSHIXIAO)) {
                                final OldsEvent.TokenShiXiaoEvent tokenmessage = new OldsEvent.TokenShiXiaoEvent();
                                EventBus.getDefault().post(tokenmessage);
                            } else {
                                message.what = -1;
                                message.obj = obj.get("Msg");
                                EventBus.getDefault().post(message);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {
                        message.what = -1;
                        message.obj = "链接失败,请检查网络";
                        EventBus.getDefault().post(message);
                    }
                }).addParams(params);
        mQueue.add(request);
    }

    //修改订单详情
    public void XiuGaiDingDan(Map<String, String> params) {
        final OldsEvent.AddDingDanEvent message = new OldsEvent.AddDingDanEvent();
        final iStringRequest request = new iStringRequest(com.android.volley.Request.Method.POST,
                Url.UPDATEDINGDAN,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {
                            JSONObject obj = new JSONObject(response.toString());
                            if (obj.get("Code").equals(SUCESS)) {
                                message.what = 1;
                                EventBus.getDefault().post(message);
                            } else if (obj.get("Code").equals(TOKENSHIXIAO)) {
                                final OldsEvent.TokenShiXiaoEvent tokenmessage = new OldsEvent.TokenShiXiaoEvent();
                                EventBus.getDefault().post(tokenmessage);
                            } else {
                                message.what = -1;
                                message.obj = obj.get("Msg");
                                EventBus.getDefault().post(message);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {
                        message.what = -1;
                        message.obj = "链接失败,请检查网络";
                        EventBus.getDefault().post(message);
                    }
                }).addParams(params);
        mQueue.add(request);
    }

    //获取用户信息
    public void GetUserInfo(Map<String, String> params) {
        final OldsEvent.GetUserInfoEvent message = new OldsEvent.GetUserInfoEvent();
        final iStringRequest request = new iStringRequest(com.android.volley.Request.Method.POST,
                Url.GETUSERINFO,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {
                            JSONObject obj = new JSONObject(response.toString());
                            if (obj.get("Code").equals(SUCESS)) {
                                UserInfoEntity entity = gson.fromJson(response.toString(), UserInfoEntity.class);
                                message.what = 1;
                                message.obj = entity;
                                EventBus.getDefault().post(message);
                            } else if (obj.get("Code").equals(TOKENSHIXIAO)) {
                                final OldsEvent.TokenShiXiaoEvent tokenmessage = new OldsEvent.TokenShiXiaoEvent();
                                EventBus.getDefault().post(tokenmessage);
                            } else {
                                message.what = -1;
                                message.obj = obj.get("Msg");
                                EventBus.getDefault().post(message);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {
                        message.what = -1;
                        message.obj = "链接失败,请检查网络";
                        EventBus.getDefault().post(message);
                    }
                }).addParams(params);
        mQueue.add(request);
    }


    //上传图片
    public void uploadImage(String qufen,String type, File file) {
        final OldsEvent.UpLoadImageEvent message = new OldsEvent.UpLoadImageEvent();
        RequestBody fileBody = RequestBody.create(MediaType.parse("multipart/form-data"), file);
//        MultipartBody.Builder builder=  new MultipartBody.Builder().setType(MultipartBody.FORM);
//
//        FormBody formBody = new FormBody.Builder().add("data", file).build();
        RequestBody requestBody = new MultipartBody.Builder()
                .setType(MultipartBody.FORM)
                .addFormDataPart("uType", type)
                .addFormDataPart("file", file.getName(), fileBody).build();

        okhttp3.Request request = new okhttp3.Request.Builder().url("http://222.132.53.42:8118/Phone/upload").post(requestBody).build();
        String Json = "";
        try {
            okhttp3.Response response = client.newCall(request).execute();
            Json = response.body().string();
            Log.i("TAG", "" + Json);
            JSONObject obj = new JSONObject(Json);
            if (obj.get("Code").equals(SUCESS)) {
                ImageEntity entity = gson.fromJson(Json, ImageEntity.class);
                message.obj = entity;
                message.arg1 = qufen;
                message.what = 1;
                EventBus.getDefault().post(message);
            } else try {
                if (obj.get("Code").equals(TOKENSHIXIAO)) {
                    final OldsEvent.TokenShiXiaoEvent tokenmessage = new OldsEvent.TokenShiXiaoEvent();
                    EventBus.getDefault().post(tokenmessage);
                } else {
                    message.what = -1;
                    message.obj = obj.get("Msg");
                    EventBus.getDefault().post(message);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        } catch (IOException e) {
            e.printStackTrace();
            message.what = -1;
            message.obj = "链接失败,请检查网络";
            EventBus.getDefault().post(message);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    //注册
    public void changPwd(Map<String, String> params) {
        final OldsEvent.RegisterEvent message = new OldsEvent.RegisterEvent();
        final iStringRequest request = new iStringRequest(com.android.volley.Request.Method.POST,
                Url.CHANGEPWD,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {
                            JSONObject obj = new JSONObject(response.toString());
                            if (obj.get("Code").equals(SUCESS)) {
                                message.what = 1;
                                EventBus.getDefault().post(message);
                            } else if (obj.get("Code").equals(TOKENSHIXIAO)) {
                                final OldsEvent.TokenShiXiaoEvent tokenmessage = new OldsEvent.TokenShiXiaoEvent();
                                EventBus.getDefault().post(tokenmessage);
                            } else {
                                message.what = -1;
                                message.obj = obj.get("Msg");
                                EventBus.getDefault().post(message);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {
                        message.what = -1;
                        message.obj = "链接失败,请检查网络";
                        EventBus.getDefault().post(message);
                    }
                }).addParams(params);
        mQueue.add(request);
    }
    //确认订单
    public void confirmOrder(Map<String, String> params) {
        final OldsEvent.ConFirmeDingDanEvent message = new OldsEvent.ConFirmeDingDanEvent();
        final iStringRequest request = new iStringRequest(com.android.volley.Request.Method.POST,
                Url.CONFIRMORDER,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {
                            JSONObject obj = new JSONObject(response.toString());
                            if (obj.get("Code").equals(SUCESS)) {
                                message.what = 1;
                                EventBus.getDefault().post(message);
                            } else if (obj.get("Code").equals(TOKENSHIXIAO)) {
                                final OldsEvent.TokenShiXiaoEvent tokenmessage = new OldsEvent.TokenShiXiaoEvent();
                                EventBus.getDefault().post(tokenmessage);
                            } else {
                                message.what = -1;
                                message.obj = obj.get("Msg");
                                EventBus.getDefault().post(message);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {
                        message.what = -1;
                        message.obj = "链接失败,请检查网络";
                        EventBus.getDefault().post(message);
                    }
                }).addParams(params);
        mQueue.add(request);
    }
    //确认订单
    public void isHaveMessage(Map<String, String> params) {
        final OldsEvent.IsHaveMessageEvent message = new OldsEvent.IsHaveMessageEvent();
        final iStringRequest request = new iStringRequest(com.android.volley.Request.Method.POST,
                Url.ISHAVEMESSAGE,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {
                            JSONObject obj = new JSONObject(response.toString());
                            if (obj.get("Code").equals(SUCESS)) {
                                message.what = 1;
                                EventBus.getDefault().post(message);
                            } else if (obj.get("Code").equals(TOKENSHIXIAO)) {
                                final OldsEvent.TokenShiXiaoEvent tokenmessage = new OldsEvent.TokenShiXiaoEvent();
                                EventBus.getDefault().post(tokenmessage);
                            } else {
                                message.what = -1;
                                message.obj = obj.get("Msg");
                                EventBus.getDefault().post(message);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {
                        message.what = -1;
                        message.obj = "链接失败,请检查网络";
                        EventBus.getDefault().post(message);
                    }
                }).addParams(params);
        mQueue.add(request);
    }
    //确认订单
    public void updateMessage(Map<String, String> params) {
        final OldsEvent.UpDateInfoEvent message = new OldsEvent.UpDateInfoEvent();
        final iStringRequest request = new iStringRequest(com.android.volley.Request.Method.POST,
                Url.UPDATEINFO,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {
                            JSONObject obj = new JSONObject(response.toString());
                            if (obj.get("Code").equals(SUCESS)) {
                                message.what = 1;
                                EventBus.getDefault().post(message);
                            } else if (obj.get("Code").equals(TOKENSHIXIAO)) {
                                final OldsEvent.TokenShiXiaoEvent tokenmessage = new OldsEvent.TokenShiXiaoEvent();
                                EventBus.getDefault().post(tokenmessage);
                            } else {
                                message.what = -1;
                                message.obj = obj.get("Msg");
                                EventBus.getDefault().post(message);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {
                        message.what = -1;
                        message.obj = "链接失败,请检查网络";
                        EventBus.getDefault().post(message);
                    }
                }).addParams(params);
        mQueue.add(request);
    }
    //确认订单
    public void addXuQiuGongYing(String Url,Map<String, String> params) {
        final OldsEvent.UpGongYingXuQiuEvent message = new OldsEvent.UpGongYingXuQiuEvent();
        final iStringRequest request = new iStringRequest(com.android.volley.Request.Method.POST,
                Url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {
                            JSONObject obj = new JSONObject(response.toString());
                            if (obj.get("Code").equals(SUCESS)) {
                                message.what = 1;
                                EventBus.getDefault().post(message);
                            } else if (obj.get("Code").equals(TOKENSHIXIAO)) {
                                final OldsEvent.TokenShiXiaoEvent tokenmessage = new OldsEvent.TokenShiXiaoEvent();
                                EventBus.getDefault().post(tokenmessage);
                            } else {
                                message.what = -1;
                                message.obj = obj.get("Msg");
                                EventBus.getDefault().post(message);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {
                        message.what = -1;
                        message.obj = "链接失败,请检查网络";
                        EventBus.getDefault().post(message);
                    }
                }).addParams(params);
        mQueue.add(request);
    }
    //获取订单详情
    public void GetHangYeXiangQing(Map<String, String> params) {
        final OldsEvent.HangYeZiXunDescEvent message = new OldsEvent.HangYeZiXunDescEvent();
        final iStringRequest request = new iStringRequest(Request.Method.POST,
                Url.GETHANGYEZIXUNDESC,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {
                            JSONObject obj = new JSONObject(response.toString());
                            if (obj.get("Code").equals(SUCESS)) {
                                HangYeZiXunEntity entity = gson.fromJson(response.toString(), HangYeZiXunEntity.class);
                                message.what = 1;
                                message.obj = entity;
                                EventBus.getDefault().post(message);
                            } else if (obj.get("Code").equals(TOKENSHIXIAO)) {
                                final OldsEvent.TokenShiXiaoEvent tokenmessage = new OldsEvent.TokenShiXiaoEvent();
                                EventBus.getDefault().post(tokenmessage);
                            } else {
                                message.what = -1;
                                message.obj = obj.get("Msg");
                                EventBus.getDefault().post(message);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {
                        message.what = -1;
                        message.obj = "链接失败,请检查网络";
                        EventBus.getDefault().post(message);
                    }
                }).addParams(params);
        mQueue.add(request);
    }
}
